<template>
  <div
    style="width: 100%; height: 100%; position: relative"
    @mouseover="showHover = item.id"
    @mouseout="showHover = null"
    class="contain"
  >
    <!-- 武将 -->
    <div style="width: 100%; height: 100%">
      <div class="header">
        <van-icon
          class="iconFont header-icon icon-chief"
          class-prefix="icon"
          size="40"
          :class="item.type == 'chief' ? 'setted' : ''"
          @click="setpolitics('chief')"
        />
        <van-icon
          class="iconFont header-icon icon-counsellor"
          class-prefix="icon"
          size="40"
          :class="item.type == 'counsellor' ? 'setted' : ''"
          @click="setpolitics('counsellor')"
        />
        <van-icon
          class="iconFont header-icon icon-politics"
          class-prefix="icon"
          size="40"
          :class="item.type == 'politics' ? 'setted' : ''"
          @click="setpolitics('politics')"
        />
        <van-icon
          class="iconFont header-icon icon-normal"
          class-prefix="icon"
          size="40"
          :class="item.type == 'normal' ? 'setted' : ''"
          @click="setpolitics('normal')"
        />
      </div>
      <div class="top">
        <div class="name">{{ item.name }}</div>
        <div class="cost">{{ item.salary }}</div>
      </div>
      <div class="mid">
        <div class="image">
          <van-icon
            class="iconFont"
            class-prefix="icon"
            size="100"
            :class="item.image"
          />
        </div>
        <div class="ablity">
          <div>{{ item.pow }}</div>
          <div>{{ item.int }}</div>
        </div>
      </div>
      <div class="bottom">
        <div v-show="item.tactic_name">战法：{{ item.tactic_name }}</div>
        <div v-show="item.stratagem_name">计谋：{{ item.stratagem_name }}</div>
        <div v-show="item.politics_name">政策：{{ item.politics_name }}</div>
      </div>
    </div>
    <!-- 武将-悬浮内容 -->
    <div
      v-show="showHover == item.id"
      :style="{
        left: index % 5 == 4 ? '-70%' : '70%',
      }"
      class="map-hover"
    >
      <div class="row" v-show="item.type">
        <span class="title"> 状态：</span> {{ showTextByType(item.type) }}
      </div>
      <div class="row" v-show="item.tactic_name">
        <span class="title"> {{ item.tactic_name }}：</span
        >{{ item.tactic_desc }}
      </div>
      <div class="row" v-show="item.stratagem_name">
        <span class="title"> {{ item.stratagem_name }}：</span>
        {{ item.stratagem_desc }}
      </div>
      <div class="row" v-show="item.politics_name">
        <span class="title"> {{ item.politics_name }}：</span>
        {{ item.politics_desc }}
      </div>
    </div>

    <van-icon
      class="iconFont water"
      class-prefix="icon"
      size="100"
      :class="`icon-${item.type}`"
    />
  </div>
</template>
<script>
import { tagList } from "@/utils/param";
export default {
  props: {
    item: {
      type: Object,
      default: () => {
        return {
          id: 999,
          name: "稻草人",
          pow: 1,
          int: 1,
          salary: 50,
          type: "normal",
          tactic_name: "恐惧",
          stratagem_name: "夜割",
          politics_name: "群鸦风暴",
          address_name: "洛阳",
          address: 0,
        };
      },
    },
    index: {
      type: Number,
      default: null,
    },
  },
  mounted() {},
  data() {
    return {
      showHover: 314159,
    };
  },
  computed: {
    gameContral() {
      let res = JSON.parse(JSON.stringify(this.$store.getters.gameContral));
      return res;
    },
  },
  methods: {
    showTextByType(type) {
      let str = "";
      /**
       * normal 待命
       * chief 主帅
       * counsellor 军师
       * politics 政策
       * defcity 守城
       */
      if (type == "defcity") {
        str = tagList[type] + this.item.address_name;
      } else {
        str = tagList[type];
      }
      return str;
    },
    setpolitics(type) {
      let gameContral = JSON.parse(
        JSON.stringify(this.$store.getters.gameContral)
      );
      let playerContral = JSON.parse(
        JSON.stringify(this.$store.getters.playerContral)
      );
      this.item.type = type;
      playerContral[gameContral.playerId].general.forEach((element) => {
        if (element.id == this.item.id) {
          element.type = type;
        }
      });
      this.$store.commit("SET_playerContral", playerContral);
    },
  },
};
</script>
<style lang="less" scoped>
.contain {
  background-color: #fff;
  border-radius: 10px;
}
.water {
  position: absolute;
  right: -10px;
  bottom: 10px;
  opacity: 0.5;
}
.desc {
  position: absolute;
  right: 0;
  bottom: 30px;
  opacity: 0.5;
  transform: rotate(-45deg);
  color: chocolate;
  font-weight: bolder;
}
.header {
  height: 10%;
  .header-icon {
    border: 2px solid #ffffff;
    cursor: pointer;
  }
  .setted {
    color: red;
    border: 2px solid #000000;
    border-radius: 4px;
  }
  .header-icon:hover {
    color: red;
    border: 2px solid #000000;
    border-radius: 4px;
  }
  padding-bottom: 10px;
}
.top {
  height: 15%;
  border: 2px solid #000000;
  border-top-right-radius: 6px;
  border-top-left-radius: 6px;
  display: flex;
  justify-content: space-between;
  .name {
    flex: 1;
  }
  .cost {
    display: inline-block;
    border-left: 2px solid #000000;
    align-self: center;
    min-width: 60px;
    padding: 0 5px;
  }
}
.mid {
  height: 30%;
  border: 2px solid #000000;
  text-align: start;
  display: flex;
  padding: 10px 0 10px 10px;
  .ablity {
    font-size: 50px;
    font-weight: bolder;
    padding: 0 0 0 20px;
    text-align: center;
  }
}
.bottom {
  text-align: start;
  height: calc(45% - 60px);
  border: 2px solid #000000;
  padding: 10px;
  border-bottom-left-radius: 6px;
  border-bottom-right-radius: 6px;

  font-size: 20px;
}
.map-hover {
  border: 2px solid #737373;
  position: absolute;
  background-color: #ffffff;
  z-index: 9999;
  width: 100%;
  min-height: 40%;
  top: 70%;
  border-radius: 6px;
  text-align: start;
  padding: 10px;
  font-size: 16px;
  z-index: 99999;
  .row {
    padding-bottom: 10px;
    .title {
      font-weight: bolder;
    }
  }
  .row + .row {
    border-top: 0.2px solid #b0b0b0;
    padding-top: 10px;
  }
}
.map-hover::-webkit-scrollbar {
  display: none;
}
</style>
